﻿using System.Collections.Specialized;
using Core.AbstractEntities;
using Operations.Entities;
using System.Runtime.Serialization;
using System;

namespace Stack.Entities
{
    /// <summary>
    /// List of elements 
    /// </summary>
    public class HpPile : HpCollection
    {
        #region HpPile Members

        /// <summary>
        /// Collection of items stored in memory
        /// </summary>
        public HpMemory Memory { get; set; }

        /// <summary>
        /// Manage the input 
        /// </summary>
        public Dispatcher Dispatcher { get; set; }
        #endregion
        /// <summary>
        /// Constructor by default
        /// </summary>
        public HpPile()
        {
            this.Memory = new HpMemory();
            this.CollectionChanged += new NotifyCollectionChangedEventHandler(HpPile_CollectionChanged);
            this.Dispatcher = new Dispatcher();
        }
        #region IHpPile Members
        /// <summary>
        /// Add element to the list
        /// </summary>
        /// <param name="element">element to add</param>
        public override void AddElement(HpElement element)
        {
            Add(element);
            Add(this.Dispatcher.GetValue(this));
        }
        #endregion
        /// <summary>
        /// Detect if any element of the collection has been changed
        /// </summary>
        void HpPile_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
                //New element has been added
                // Nothing for the moment
                return;
            if (e.Action == NotifyCollectionChangedAction.Remove)
                //New element has been deleted
                // Nothing for the moment
                return;
        }
    }
}